
import { useQuery } from "@tanstack/react-query";
import { SwitchCommand } from "./command/switch";
import { BodyState } from "./state/body";
import { SwitchState } from "./state/switch";
import { fetcher } from "~/lib/fetcher";




export function DeviceCommand({ device }: { device: Pick<Device, "guid" | "type"> }) {
    switch (device.type) {
        case 17:
            return <SwitchCommand device={device} />
    }

    return (<></>);


}
export function DeviceState({ device }: { device: Pick<Device, "guid" | "type"> }) {

    useQuery({
        queryKey: ["state", device.guid],
        queryFn: async () => {
            const response = await fetcher<Response>(`http://localhost:3333/states/${device.guid}`);
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            return response.json();

        }
    });


    switch (device.type) {
        case 10:
        case 19:
            return <BodyState device={device} />
        case 17:
            return <SwitchState device={device} />
    }

    return (<></>);


}

